/*
 * lab2.fx
 *
 * Created on 23.09.2009, 21:06:22
 */

package javafx179labs.vetkin.lab2;

/**
 * @author Алексей
 */
 
import javafx.scene.*;
import javafx.stage.* ;
import javafx.scene.control.*;

var texts: String[];
var str="" ;

var List: ListView = ListView {
                       items: bind texts
                       layoutX:2 layoutY:60
                       height: 200
                       width: 120
                       onMouseClicked: function(event) {
                               if (List.selectedIndex==-1) {
                                       Txt.visible=false ;
                                       edit.visible=false ;
                                       delet.visible=false ;}
                               Txt.visible=true ;
                               edit.visible=true ;
                               delet.visible=true ;
                               Txt.text=texts[List.selectedIndex] ;
                               
                               }
                       }

var Txt: TextBox = TextBox {
                    columns: 12
                    selectOnFocus: true
                    layoutX: 150 layoutY:100
                    text: texts[List.selectedIndex]
                    visible: false
                    }

var edit: Button = Button {
                    text:"Редактировать"
                    layoutX:150 layoutY:130
                    visible: false
                    action: function() {
                            if (texts[List.selectedIndex]!="")
                            texts[List.selectedIndex]=Txt.text;
                            edit.visible=false ;
                            delet.visible=false ;
                            Txt.visible=false ;
                            }
                    }

var delet: Button = Button {
                    text:"Удалить"
                    layoutX:270 layoutY:130
                    visible: false
                    action: function() {
                            delete texts[List.selectedIndex];
                            Txt.text="";
                            edit.visible=false ;
                            delet.visible=false ;
                            Txt.visible=false ;
                        }
                    }

Stage {
    height: 300
    width: 400
    title: "List"
    scene: Scene {
        content: [
                /////////////////////////////
                TextBox {
                    columns: 12
                    selectOnFocus: true
                    layoutX: 2 layoutY:20
                    text: bind str with inverse
                    }
                //////////////////////////////
                Button {
                    text:"Добавить в список"
                    layoutX:150 layoutY:20
                    action: function() {
                            if (str!="")insert str into texts;
                            str=""
                        }
                    }
                /////////////////////////////////
                List, Txt, edit, delet,

        ]
    }
}


